<?php
require_once('../../includes/classes/core.php');
header('Content-Type: application/json');
$start = $_REQUEST['start'];
$end   = $_REQUEST['end'];
$agent = $_REQUEST['agent'];
$queuet = $_REQUEST['queuet'];

$start = $db->convertDateTime($start);
$end = $db->convertDateTime($end);

$result = mysql_query("SELECT   COUNT(*) AS `count`,
                    			CONCAT('ნაპასუხბი',' ',COUNT(*)) AS `cause`
                        FROM 	`asterisk_incomming`
                        WHERE	`wait_time` IS NOT NULL 
                        AND `asterisk_incomming`.`call_datetime` >= '$start'
                        AND `asterisk_incomming`.`call_datetime` <= '$end' 
                        AND dst_queue IN ($queuet) 
                        AND dst_extension in ($agent)
                        UNION ALL
                        SELECT 	COUNT(*) AS `count`,
                        		CONCAT('უპასუხო',' ',COUNT(*)) AS `cause`
                        FROM 	`asterisk_incomming`
                        WHERE	`disconnect_cause`='ABANDON'  
                        AND `asterisk_incomming`.`call_datetime` >= '$start'
                        AND `asterisk_incomming`.`call_datetime` <= '$end' 
                        AND dst_queue IN ($queuet) 
                        ");


$row = array();
$rows = array();
while($r = mysql_fetch_array($result)) {
	$row[0] = $r[1];
	$row[1] = $r[0];
	array_push($rows,$row);
}

//mysql_close();
//require_once('../../includes/classes/core.php');

//$row_done_blank = mysql_query(" SELECT 	COUNT(*) AS `count`,
		//CONCAT('დამუშავებული-',COUNT(*)) AS `cause1`
		//FROM `incomming_call`
		//WHERE DATE(date) >= '$start' AND DATE(date) <= '$end' AND phone != '' ");

//$row1 = array();
//while($r1 = mysql_fetch_array($row_done_blank)) {
	//$row1[0] = $r1[1];
	//$row1[1] = $r1[0];
	//array_push($rows,$row1);
//}

echo json_encode($rows, JSON_NUMERIC_CHECK);

?>